/*
 * Copyright (c) 2010 Zauber S.A.  -- All rights reserved
 */
package ar.edu.itba.ia2010.geneticos.motor.api.sintaxistree.generators;

import java.util.Random;

import ar.edu.itba.ia2010.geneticos.motor.api.sintaxistree.Expresion;
import ar.edu.itba.ia2010.geneticos.motor.api.sintaxistree.ExpresionGenerator;
import ar.edu.itba.ia2010.geneticos.motor.api.sintaxistree.impl.ExpresionPrimitive;

/**
 * In the Full method (so named because it generates full
 * trees) nodes are taken at random from the function set until this maximum 
 * tree depth is reached, and beyond that depth only terminals can be chosen
 * 
 * @author Juan F. Codagnone
 * @since Mar 28, 2010
 */
public class FullExpresionGenerator extends AbstractExpresionGenerator {
    
    /** Creates the FullExpresionGenerator. */
    public FullExpresionGenerator(final ExpresionPrimitive []primitives) {
        super(primitives);
    }
    
    /** @see ExpresionGenerator#generate(Random, int) */
    public final Expresion generate(final Random random, final int maxDepth) {
        final Expresion ret;
        if(maxDepth > 0) {
            ret = nextOperation(random, maxDepth);
        } else {
            ret = nextTerminal(random, maxDepth);
        }
        return ret;
    }
}
